package com.libbase.kotlin.base

import android.arch.lifecycle.LifecycleObserver
import android.os.Bundle
import com.base.activity.BaseActivity
import com.base.kotlin.mvvm.BaseVmPresenter
import com.base.kotlin.mvvm.IView

/**
 * @author zhouzechao
 * Activity的mvvm基类
 */
abstract class BaseVmKActivity<T : BaseVmPresenter<*>> : BaseActivity(), IView.DefaultView {

    protected var mPresenter: T? = null

    abstract fun bindViewToPresenter(): T?

    override fun onCreate(savedInstanceState: Bundle?) {
        mPresenter = bindViewToPresenter()
        mPresenter?.let {
            lifecycle.addObserver(it as LifecycleObserver)
        }
        super.onCreate(savedInstanceState)
    }

    override fun onDestroy() {
        super.onDestroy()
        mPresenter?.let { lifecycle.removeObserver(it as LifecycleObserver) }
    }

    override fun onDefaultSuccess(action: Int, data: Any?) {

    }
}